package cn.didi.feidi.location.activity.base;

import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.amap.api.maps.AMap;
import com.amap.api.maps.MapView;
import com.amap.api.maps.model.Marker;

/**
 * Created by jinxiong on 2017/7/11.
 */

public abstract class BaseMapActivity extends AppCompatActivity
        implements AMap.InfoWindowAdapter, AMap.OnMarkerClickListener {

    protected AMap mAMap;//mapView 管理类
    protected MapView mMapView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initView(savedInstanceState);//在此方法中赋值mapView了
        mMapView.onCreate(savedInstanceState);
        initVariables();//在此方法赋值了AMap
        initVar();
        addListener();
        loadData();
    }

    protected void initVar() {
        mAMap.setOnMarkerClickListener(this);//marker 点击接口
        mAMap.setInfoWindowAdapter(this);//info window 自定义接口
    }

    @Override
    protected void onPause() {
        super.onPause();
        mMapView.onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        mMapView.onResume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mMapView.onDestroy();

    }

    @Override
    public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
        super.onSaveInstanceState(outState, outPersistentState);
        mMapView.onSaveInstanceState(outState);
    }


    @Override
    public View getInfoContents(Marker marker) {
        return null;
    }


    /**
     * 在此方法中调用setContentView
     * 初始化view，必须为mMapView赋值
     */
    protected abstract void initView(Bundle saveInstanceState);

    /**
     * 初始化其他变量,必须在此为mAMap赋值
     */
    protected abstract void initVariables();

    /****
     *加载数据
     */
    protected abstract void loadData();

    protected abstract void addListener();
}
